<script setup>
import { ref, onMounted } from 'vue'

const starsCount = ref(800) // 星星数量
const distance = ref(900)  // 间距

// 初始化星星样式
const starStyles = ref([])
for (let i = 0; i < starsCount.value; i++) {
  const speed = 0.2 + Math.random() * 1
  const thisDistance = distance.value + Math.random() * 300
  starStyles.value.push({
    transformOrigin: `0 0 ${thisDistance}px`,
    transform: `
      translate3d(0,0,-${thisDistance}px)
      rotateY(${Math.random() * 360}deg)
      rotateX(${Math.random() * -50}deg)
      scale(${speed},${speed})`
  })
}
</script>

<template>
  <view class="bg">
    <view class="body">
      <!-- 星星容器 -->
      <view class="stars">
        <view 
          v-for="(style, index) in starStyles" 
          :key="index" 
          class="star"
          :style="style"
        ></view>
      </view>
    </view>
  </view>
</template>

<style scoped>
.bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: -1;
  overflow: hidden;
}

.body {
  position: absolute;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  background: radial-gradient(
    200% 105% at top center,
    #0a0a1a 10%,
    #0c1446 40%,
    #1b2947 65%,
    rgba(100, 65, 165, 0.7) 80%,
    rgba(186, 120, 182, 0.4) 90%,
    rgba(50, 15, 60, 0.9) 100%
  );
  background-attachment: fixed;
  overflow: hidden;
}

@keyframes rotate {
  0% {
    transform: perspective(400px) rotateZ(20deg) rotateX(-40deg) rotateY(0);
  }
  100% {
    transform: perspective(400px) rotateZ(20deg) rotateX(-40deg) rotateY(-360deg);
  }
}

.stars {
  transform: perspective(500px);
  transform-style: preserve-3d;
  position: absolute;
  perspective-origin: 50% 100%;
  left: 45%;
  animation: rotate 90s infinite linear;
  bottom: 0;
}

.star {
  width: 2px;
  height: 2px;
  background-color: #fffacd;
  box-shadow: 0 0 8px rgba(179, 150, 255, 0.6);
  position: absolute;
  left: 0;
  top: 0;
  backface-visibility: hidden;
}
</style>